package conson.tech.manage.facade.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import conson.tech.manage.activity.service.TicketRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.List;


@Slf4j
@Component
public class ScheduleOperationJob {


    @Autowired
    private TicketRecordService ticketRecordService;
    /**
     * 定时过期票券
     *
     * @return
     */
    @XxlJob("scheduledCancelTicket")
    public ReturnT<String> scheduledCancelTicket(String param) {
        XxlJobLogger.log("ScheduleMessageJob --> 定时过期票券 定时器开始");
        log.info("ScheduleJobProvider --> 定时过期票券 定时器开始, time{}", LocalDateTime.now());
        try {
            List<Long> idList = ticketRecordService.queryTimeOutTicket();
            if (!CollectionUtils.isEmpty(idList)){
                ticketRecordService.updateTimeOutTicketRecordList(idList);
            }
            XxlJobLogger.log("ScheduleMessageJob --> 定时过期票券 定时器完成, time{}", LocalDateTime.now());
            log.info("ScheduleMessageJob --> 定时过期票券 定时器完成, time{}", LocalDateTime.now());
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            log.error("ScheduleMessageJob --> 定时过期票券 定时器异常, time{}", LocalDateTime.now(), e);
            return ReturnT.FAIL;
        }
    }
}
